from fastapi import status


class BaseException(Exception):
    """应用自定义异常基类"""
    
    def __init__(self, detail: str = "服务器错误", status_code: int = status.HTTP_500_INTERNAL_SERVER_ERROR):
        self.detail = detail
        self.status_code = status_code
        super().__init__(self.detail)


class NotFoundException(BaseException):
    """资源未找到异常"""
    
    def __init__(self, detail: str = "请求的资源不存在"):
        super().__init__(detail=detail, status_code=status.HTTP_404_NOT_FOUND)


class BadRequestException(BaseException):
    """请求参数错误异常"""
    
    def __init__(self, detail: str = "请求参数错误"):
        super().__init__(detail=detail, status_code=status.HTTP_400_BAD_REQUEST)


class UnauthorizedException(BaseException):
    """未授权异常"""
    
    def __init__(self, detail: str = "未授权访问"):
        super().__init__(detail=detail, status_code=status.HTTP_401_UNAUTHORIZED)


class ForbiddenException(BaseException):
    """禁止访问异常"""
    
    def __init__(self, detail: str = "禁止访问"):
        super().__init__(detail=detail, status_code=status.HTTP_403_FORBIDDEN)